<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="Generator" content="EditPlus®">
		<meta name="Author" content="">
		<meta name="Keywords" content="">
		<meta name="Description" content="">
		<title>Document</title>
		<script type="text/javascript" src="./js/mico-dc-0.1.js"></script>

		<script>
			// 打开MDNS
			function openmDNS() {
				var servName = "_easylink._tcp.local.";
				$mico.startmDNS(servName, function(ret, err) {
					alert("openmDNS = " + ret);
				});
			}

			// 关闭MDNS
			function stopmDNS() {
				$mico.stopmDNS(function(ret, err) {
					alert("stopmDNS = " + ret);
				});
			}

			// 获取SSID
			function getSSId() {
				$mico.getSSId(function(ret, err) {
					alert("getSSId = " + ret);
				});
			}

			// 开始配网
			function startEasyLink() {
				var wifiname = "gg";
				var wifipsw = "22222222";
				$mico.startEasyLink(wifiname, wifipsw, function(ret, err) {
					alert("startEasyLink = " + ret);
				});
			}

			// 结束配网
			function stopEasyLink() {
				$mico.stopEasyLink(function(ret, err) {
					alert("stopEasyLink = " + ret);
				});
			}

			// 打开matt服务
			function startMqtt() {
				alert("startmqtt");
				var host = "api.easylink.io";
				var username = "";
				var password = "";
				var clientID = "clientId-abcdedf";
				var topic = "d64f517c/c8934691813c/#";
				$mico.startMqtt(host, username, password, clientID, topic, function(ret, err) {
					alert("ret = " + ret);
				});
			}

			// 开始接受消息
			function recvMqttMsg() {
				$mico.recvMqttMsg(function(ret, err) {
					alert("subs = " + ret);
				});
			}

			// 发送指令
			function publishCommand() {
				var topic = "d64f517c/c8934691813c/in/write/app1";
				var command = '{"4":true,"5":0, "6":100, "7":100}';
				$mico.publishCommand(topic, command, function(ret, err) {
					alert("subs = " + ret);
				});
			}

			// 停止接受信息
			function stopRecvMqttMsg() {
				$mico.stopRecvMqttMsg(function(ret, err) {
					alert("subs = " + ret);
				});
			}

			// 关闭mqtt服务
			function stopMqtt() {
				$mico.stopMqtt(function(ret, err) {
					alert("subs = " + ret);
				});
			}
		</script>

	</head>
	<body>
		<br/>
		<br/>
		<input type="button" onclick="openmDNS()" value="搜索设备"/>
		<br/>
		<br/>
		<input type="button" onclick="stopmDNS()" value="停止搜索"/>
		<br/>
		<br/>
		<input type="button" onclick="getSSId()" value="获取当前SSID"/>
		<br/>
		<br/>
		<input type="button" onclick="startEasyLink()" value="开始EasyLink"/>
		<br/>
		<br/>
		<input type="button" onclick="stopEasyLink()" value="停止EasyLink"/>
		<br/>
		<br/>
		<input type="button" onclick="startMqtt()" value="打开MQTT"/>
		<br/>
		<br/>
		<input type="button" onclick="recvMqttMsg()" value="接受消息"/>
		<br/>
		<br/>
		<input type="button" onclick="stopRecvMqttMsg()" value="停止接受消息"/>
		<br/>
		<br/>
		<input type="button" onclick="stopMqtt()" value="关闭MQTT"/>
		<br/>
		<br/>
		<input type="button" onclick="publishCommand()" value="发送指令"/>
	</body>
</html>
